package com.minelx.sequence.pattern.variable;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class VariableManager implements IVariableManager {
	private final Map<String, Object> keyValues;

	public VariableManager() {
		keyValues = new HashMap<>();
	}

	@Override
	public void set(String key, Object value) {
		keyValues.put(key, value);
	}

	@Override
	public Object get(String key) {
		if (!keyValues.containsKey(key)) {
			throw new IllegalArgumentException("key doesn't exists: " + key);
		}
		return keyValues.get(key);
	}

	@Override
	public Consumer<Object> setterOf(String variableName) {
		return value -> set(variableName, value);
	}

	@Override
	public String toString() {
		return "VariableManager{" +
				"keyValues=" + keyValues +
				'}';
	}
}
